home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1995.rar / 1995 / JUN / CA9506 / ca_list.txt
Text File  |  1995-05-09  |  10KB  |  446 lines

  1. ***************************************************************
  2. Begin Listing 1 -- Complete VB Code for Project
  3. ***************************************************************
  4. Begin Form Form1 
  5.  Caption     =  "Form1"
  6.  ClientHeight  =  3825
  7.  ClientLeft   =  1095
  8.  ClientTop    =  1485
  9.  ClientWidth   =  3555
  10.  Height     =  4230
  11.  Left      =  1035
  12.  LinkTopic    =  "Form1"
  13.  ScaleHeight   =  3825
  14.  ScaleWidth   =  3555
  15.  Top       =  1140
  16.  Width      =  3675
  17.  Begin CommandButton Command4 
  18.   Caption     =  "Control 1"
  19.   Height     =  495
  20.   Index      =  1
  21.   Left      =  240
  22.   TabIndex    =  5
  23.   Top       =  2280
  24.   Width      =  1215
  25.  End
  26.  Begin CommandButton Command4 
  27.   Caption     =  "Control 0"
  28.   Height     =  495
  29.   Index      =  0
  30.   Left      =  240
  31.   TabIndex    =  4
  32.   Top       =  1800
  33.   Width      =  1215
  34.  End
  35.  Begin CommandButton Command3 
  36.   Caption     =  "Case"
  37.   Height     =  495
  38.   Left      =  240
  39.   TabIndex    =  3
  40.   Top       =  1080
  41.   Width      =  1215
  42.  End
  43.  Begin TextBox Text1 
  44.   Height     =  3615
  45.   Left      =  1560
  46.   MultiLine    =  -1 'True
  47.   TabIndex    =  2
  48.   Text      =  "Text1"
  49.   Top       =  120
  50.   Width      =  1935
  51.  End
  52.  Begin CommandButton Command2 
  53.   Caption     =  "Loop2"
  54.   Height     =  495
  55.   Left      =  240
  56.   TabIndex    =  1
  57.   Top       =  600
  58.   Width      =  1215
  59.  End
  60.  Begin CommandButton Command1 
  61.   Caption     =  "Loop1"
  62.   Height     =  495
  63.   Left      =  240
  64.   TabIndex    =  0
  65.   Top       =  120
  66.   Width      =  1215
  67.  End
  68.  Begin Label Label1 
  69.   BorderStyle   =  1 'Fixed Single
  70.   Caption     =  "Control Status"
  71.   Height     =  615
  72.   Left      =  240
  73.   TabIndex    =  6
  74.   Top       =  2880
  75.   Width      =  1215
  76.  End
  77. End
  78.  
  79. Sub CaseTest ()
  80.  Dim NumToTest As Integer
  81.  Dim Msg As String
  82.  Dim Title As String
  83.   
  84.  Msg = "Enter a value between 1 and 10."
  85.  Title = "CaseTest"
  86.  Do
  87.   NumToTest = InputBox(Msg, Title, "1")
  88.   Loop Until NumToTest >= 1 And NumToTest <= 10
  89.   MsgBox "You entered " & NumToTest ' Display message.
  90.   Select Case NumToTest
  91. Case 1, 3, 5, 7, 9: Msg = "odd number"
  92. Case 2, 4, 6, 8, 10: Msg = "even number"
  93.   End Select
  94.   MsgBox Msg
  95. End Sub
  96.  
  97. Sub Command1_Click ()
  98.  Loop1
  99. End Sub
  100.  
  101. Sub Command2_Click ()
  102.  Loop2
  103. End Sub
  104.  
  105. Sub Command3_Click ()
  106.  CaseTest
  107. End Sub
  108.  
  109. Sub Command4_Click (Index As Integer)
  110.  If Index = 0 Then
  111.   Label1.Caption = "Control array 0 pressed."
  112.  Else
  113.   Label1.Caption = "Control array 1 pressed."
  114.  End If
  115. End Sub
  116.  
  117. Sub Loop1 ()
  118.  Dim I As Integer
  119.  Dim J As Integer
  120.  Static TestArray(10, 10)
  121.  For I = 1 To 10
  122.   For J = 1 To 10
  123.  TestArray(I, J) = I
  124.   Next J
  125.  Next I
  126.  MsgBox "Test Array 10x10 filled."
  127. End Sub
  128.  
  129. Sub Loop2 ()
  130.  Dim Dice1 As Integer
  131.  Dim Flag As Integer
  132.  Randomize
  133.  Text1.Text = "Tossing"
  134.  Flag = 77
  135.  While Flag = 77
  136.   Dice1 = Int(6 * Rnd + 1)
  137.   If Dice1 < 6 Then
  138.  Text1.Text = Text1.Text & Str(Dice1)
  139.   Else
  140.  Text1.Text = Text1.Text & Str(Dice1) & " !Bingo!"
  141.  Flag = 1
  142.   End If
  143.  Wend
  144. End Sub
  145. ***************************************************************
  146. End Listing 1 
  147. ***************************************************************
  148.  
  149.  
  150. ***************************************************************
  151. Begin Listing 2 -- Code produced by Conversion Assistant
  152. ***************************************************************
  153. unit loops2;
  154. { Delphi Project translation }
  155. { From EarthTrek Inc.    }
  156.  
  157. interface
  158.  
  159. uses VB,
  160. SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  161. Forms, Dialogs, StdCtrls;
  162. { append modal form names here }
  163.  
  164. type
  165.  TForm1 = class(TForm)
  166.  Command4IndeX1: TButton;
  167.  Command4IndeX0: TButton;
  168.  Command3: TButton;
  169.  Text1: TEdit;
  170.  Command2: TButton;
  171.  Command1: TButton;
  172.  Label1: TLabel;
  173.  procedure Command1_Click(Sender: TObject);
  174.  procedure Command2_Click(Sender: TObject);
  175.  procedure Command3_Click(Sender: TObject);
  176.  procedure Command4_Click(Sender: TObject);
  177.  { Array function helpers }
  178.  function Command4(ind: integer): TButton;
  179. private
  180.  { Private declarations }
  181. public
  182.  { Public declarations }
  183.  procedure CaseTest;
  184.  procedure Loop1;
  185.  procedure Loop2;
  186. end;
  187.  
  188. var
  189.  iForm1: TForm1;
  190.  
  191. implementation
  192.  
  193. {$R *.DFM}
  194.  
  195. {----------------------------------------}
  196. { Array function helpers - code body }
  197.  
  198.  function TForm1.Command4(ind: integer): TButton;
  199.  begin
  200.   result := TButton(FindComponent('Command4IndeX'+VBstr(ind)));
  201.  end;
  202. {----------------------------------------}
  203. procedure TForm1.CaseTest;
  204. Var
  205.  NumToTest: integer;
  206.  Msg: string;
  207.  Title: string;
  208. begin
  209.   (  )
  210.   Msg := 'Enter a value between 1 and 10.';
  211.   Title := 'CaseTest';
  212.   Do;
  213. NumToTest := InputBox(Msg, Title, '1');
  214.   Loop Until NumToTest >= 1 And NumToTest <= 10;
  215.   MsgBox 'You entered ' + NumToTest { Display message.};
  216.   case NumToTest of
  217. 1: begin;
  218. end;
  219. 2: begin;
  220. end;
  221. end; {c a s e}
  222.   MsgBox Msg;
  223. end;
  224. {----------------------------------------}
  225. procedure TForm1.Command1_Click(Sender: TObject);
  226. begin
  227.     Loop1;
  228. end;
  229. {----------------------------------------}
  230. procedure TForm1.Command2_Click(Sender: TObject);
  231. begin
  232.     Loop2;
  233. end;
  234. {----------------------------------------}
  235. procedure TForm1.Command3_Click(Sender: TObject);
  236. begin
  237.     CaseTest;
  238. end;
  239. {----------------------------------------}
  240. procedure TForm1.Command4_Click(Sender: TObject);
  241. begin
  242.   If VBIndex(Sender) = 0 Then
  243.   begin
  244. Label1.Caption := 'Control array 0 pressed.';
  245.   end
  246.   else
  247.   begin
  248. Label1.Caption := 'Control array 1 pressed.';
  249.   end;
  250. end;
  251. {----------------------------------------}
  252. procedure TForm1.Loop1;
  253. Var
  254.  I: integer;
  255.  J: integer;
  256. begin
  257.   Static TestArray(10, 10);
  258.   For I := 1 To 10 do
  259.   begin
  260. For J := 1 To 10 do
  261.  begin
  262.   TestArray(I, J) := I;
  263.  end;
  264.   end;
  265.   MsgBox 'Test Array 10x10 filled.';
  266. end;
  267. {----------------------------------------}
  268. procedure TForm1.Loop2;
  269. Var
  270.  Dice1: integer;
  271.  Flag: integer;
  272. begin
  273.   Randomize;
  274.   Text1.Text := 'Tossing';
  275.   Flag := 77;
  276.   While Flag = 77;
  277. Dice1 := Int(6 * Rnd + 1);
  278. If Dice1 < 6 Then
  279.  begin
  280.      Text1.Text := Text1.Text + VBstr(Dice1);
  281.  end
  282.  else
  283.  begin
  284.      Text1.Text := Text1.Text + VBstr(Dice1) + ' i.iBingo.';
  285.   Flag := 1;
  286.  end;
  287.   Wend;
  288. end;
  289.  
  290. begin
  291.  RegisterClasses( [TForm1,TButton,TEdit,TLabel] );
  292.  iForm1 := TForm1.Create(Application);
  293. end.
  294. ***************************************************************
  295. End Listing 2
  296. ***************************************************************
  297.  
  298.  
  299. ***************************************************************
  300. Begin Listing 3 -- Corrected Code
  301. ***************************************************************
  302. unit loops2;
  303. { GaryÆs translation of  }
  304. { Delphi Project translation }
  305. { From EarthTrek Inc.    }
  306.  
  307. interface
  308.  
  309. uses VB,
  310. SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  311. Forms, Dialogs, StdCtrls;
  312. { append modal form names here }
  313.  
  314. type
  315.  TForm1 = class(TForm)
  316.   Command4IndeX1: TButton;
  317.   Command4IndeX0: TButton;
  318.   Command3: TButton;
  319.   Command2: TButton;
  320.   Command1: TButton;
  321.   Label1: TLabel;
  322.   Memo1: TMemo;
  323.   procedure Command1_Click(Sender: TObject);
  324.   procedure Command2_Click(Sender: TObject);
  325.   procedure Command3_Click(Sender: TObject);
  326.   procedure Command4_Click(Sender: TObject);
  327.   { Array function helpers }
  328.   function Command4(ind: integer): TButton;
  329. private
  330.   { Private declarations }
  331. public
  332.   { Public declarations }
  333.   procedure CaseTest;
  334.   procedure Loop1;
  335.   procedure Loop2;
  336. end;
  337.  
  338. var
  339.  iForm1: TForm1;
  340.  
  341. implementation
  342.  
  343. {$R *.DFM}
  344.  
  345. {----------------------------------------}
  346. { Array function helpers - code body }
  347.  
  348. function TForm1.Command4(ind: integer): TButton;
  349. begin
  350.  result := TButton(FindComponent('Command4IndeX'+VBstr(ind)));
  351. end;
  352. {----------------------------------------}
  353. procedure TForm1.CaseTest;
  354. Var
  355.  NumToTest: Integer;
  356.  StrNum : String;
  357.  Msg: string;
  358.  Title: string;
  359.  Code: Integer;
  360. begin
  361.  Msg := 'Enter a value between 1 and 10.';
  362.  Title := 'CaseTest';
  363.  Repeat
  364.   StrNum := InputBox(Msg, Title, '1');
  365.   Val(StrNum,NumToTest,Code);
  366.  Until (NumToTest >= 1) And (NumTotest <= 10);
  367.  ShowMessage('You entered ' + StrNum); { Dis